//点击返回顶部
let scrolltop = document.documentElement.scrollTop
$("#foot ul .li3").click(function () {
    $("html,body").animate({ scrollTop: 0 }, 500)
})
//点击图标返回上一页
$("#header .fh").click(function(){
    window.location.href="sqk_list.html"
})
//根据lis页面点击跳转到详情页面的local href 并且 拼接?productid=x
//http://127.0.0.1:5500/%E4%B8%87%E9%94%8B%E6%99%BA%E6%85%A7/pages/sqk_detail.html?productId=20
//拿到传递的商品id
let reg = /([^&=]+)=?([^&]*)/g
let str = window.location.href
let strId = parseInt(reg.exec(str)[2])
console.log(strId);
//请求对应的数据渲染页面
fetch(`http://chst.vip:1234/api/getmoneyctrlproduct?productid=${strId}`)
.then(body=>body.json())
.then(res=>{
    let resultobject = res.result[0]
    console.log(resultobject);
    let str=""
    //把img标签地址匹配出来----------------------
    let address = resultobject.productImgSm
    let reg=/^<[^<]+\s+src="([^''""]*)"/
    address=reg.exec(address)[1]
    console.log(address);
    //----------------------------------------
    str+=`
    <div class="xqmod">
        <h4>${resultobject.productName}</h4>
        <p class="product">
            <span class="pt left">${resultobject.productFrom}|${resultobject.productTime}</span>
            <span class="pt right">${resultobject.productTips}</span>
        </p>
        <div class="text">
            <img src="${address}" alt="" class="spic">
            <p>${resultobject.productInfo2}</p>
            <img src="${address}" alt="" class="mpic">
        </div>
    </div>
    <ul class="yhmod">
        ${resultobject.productCity}
    </ul>
    <div class="gmmod">
        <a href="#">前往购买</a>
        <img src="http://chst.vip:8081/for-stu/wfzh/images/mmbweixin2.png" alt="">
    </div>
    <div class="plmod">
        ${resultobject.productComment}
    </div>
    <div id="more">
        <p>更多优惠信息&gt;&gt;</p>
    </div>
    `
    $("#main").html(str)
})
